if(MSVC)
	cmake_minimum_required(VERSION 3.5)
else()
	cmake_minimum_required(VERSION 3.0)
endif()

cmake_policy(SET CMP0048 NEW)

set(PRO_VERSION 1.0.0)
set(PROJECT_VERSION_MAJOR 1)
set(PROJECT_VERSION_MINOR 0)
set(PROJECT_VERSION_PATCH 0)

add_definitions(-D __BUILD_JXQ_LIB)

if(MSVC)
	add_definitions(-D _CRT_SECURE_NO_WARNINGS)
endif()

# set(CMAKE_BUILD_TYPE Debug)

if((${CMAKE_BUILD_TYPE}) STREQUAL (Debug))
	add_definitions(-D J_DEBUG)
else()
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
endif()

#-----------------------------------------------------------------------------------

if(MSVC)
	set(CMAKE_CXX_STANDARD 11)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W4")

else()
	include(CheckCXXCompilerFlag)

	CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
	CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)

	if(COMPILER_SUPPORTS_CXX11)
		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
	elseif(COMPILER_SUPPORTS_CXX0X)
		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall")
	else()
		message(status " ** The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
	endif()

endif()

#-----------------------------------------------------------------------------------

set(VERSIONINFO_RC )

macro(project_version_conf)
	if(MSVC)
		set(VERSIONINFO_RC
			${CMAKE_BINARY_DIR}/${PROJECT_NAME}/.${PROJECT_NAME}_version_win.rc)
		configure_file(
			${CMAKE_SOURCE_DIR}/.version_win.rc.in
			${VERSIONINFO_RC}
			)
		set(VERSIONINFO_RC )  # *.rc(2): error RC2135: file not found: 1 !!! fuck...
	endif()
endmacro()

#-----------------------------------------------------------------------------------

macro(output_conf)
	set(CPRO_BUILD_PATH ${PROJECT_SOURCE_DIR}/../../build)
	set(LIBRARY_OUTPUT_PATH ${CPRO_BUILD_PATH})
	set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CPRO_BUILD_PATH})
	set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PRO_VERSION})
endmacro()
